package com.ruoyi.repairCar.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.repairCar.domain.MaintenanceRecord;
import com.ruoyi.repairCar.service.IMaintenanceRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维修记录Controller
 * 
 * @author djt
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/repairRecord")
public class MaintenanceRecordController extends BaseController
{
    @Autowired
    private IMaintenanceRecordService maintenanceRecordService;

    /**
     * 查询维修记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MaintenanceRecord maintenanceRecord)
    {
        startPage();
        List<MaintenanceRecord> list = maintenanceRecordService.selectMaintenanceRecordList(maintenanceRecord);
        return getDataTable(list);
    }

    /**
     * 根据会员id查询维修记录列表和会员数据
     */
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(maintenanceRecordService.selectMaintenanceRecordByRecordId(recordId));
    }

    /*
    * 根据订单号查询维修记录列表和会员数据！！！！！！！！
    * */
    @GetMapping(value = "/maintenanceNo/{maintenanceNo}")
    public AjaxResult getInfoByMaintenanceNo(@PathVariable("maintenanceNo") String maintenanceNo)
    {
        return success(maintenanceRecordService.selectMaintenanceRecordByMaintenanceNo(maintenanceNo));
    }

    /**
     *新增用户预约维修接口
     */
    @Log(title = "维修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintenanceRecord maintenanceRecord)
    {
        return toAjax(maintenanceRecordService.insertMaintenanceRecord(maintenanceRecord));
    }

    /**
     * 修改维修记录
     */
    @Log(title = "维修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaintenanceRecord maintenanceRecord)
    {
        return toAjax(maintenanceRecordService.updateMaintenanceRecord(maintenanceRecord));
    }

    /**
     * 用户取消预约
     */
    @Log(title = "维修记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(maintenanceRecordService.deleteMaintenanceRecordByRecordIds(recordIds));
    }
}
